package com.bwie.es.controller;

import com.alibaba.fastjson.JSONObject;
import com.bwie.common.domain.Shop;
import com.bwie.common.domain.Statistics;
import com.bwie.common.domain.request.ShopRequest;
import com.bwie.common.result.PageResult;
import com.bwie.common.result.Result;
import com.bwie.es.service.EsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@Slf4j
public class EsController {

    @Autowired
    private EsService service;

    @Autowired
    private HttpServletRequest httpServletRequest;

    /**
     * ES查询店铺列表
     * @param request
     * @return
     */
    @PostMapping("/esInquire")
    public Result<PageResult<Shop>> esInquire(@RequestBody ShopRequest request){
        log.info("功能:ES查询店铺列表");
        log.info("请求方法:{}"+httpServletRequest.getMethod());
        log.info("请求路径:{}"+httpServletRequest.getRequestURL());
        log.info("请求参数:{}"+ JSONObject.toJSONString(request));
        Result<PageResult<Shop>> pageResultResult = service.esInquire(request);
        log.info("功能:ES查询店铺列表");
        log.info("请求方法:{}"+httpServletRequest.getMethod());
        log.info("请求路径:{}"+httpServletRequest.getRequestURL());
        log.info("响应结果:{}"+ JSONObject.toJSONString(pageResultResult));
        return pageResultResult;
    }


    @GetMapping("/queryCount")
    public Result<List<Statistics>> queryCount(){
        List<Statistics> statistics = service.queryCount();
        return Result.success(statistics);
    }
}
